<template>
    <view class="box_1">
        <view class="business-record">
            <view class="r-data">
                <view class="top_1_box">
                    <view  @tap="hanldeShowData1()"><image class="date_image" src="../../static/img/cash_date.png"></image></view>
                    <view class="d-time" @tap="hanldeShowData1()">日期选择</view>
                    <view @tap="hanldeShowData1()"><image  class="date_image_2" src="../../static/img/sale_arrow_2.png"/></view>

                </view>

                <view class="business_number">
                    <view @tap="selectShow" class="watch_all">{{selected_type_name}}<image  class="date_image_2" src="../../static/img/sale_arrow_2.png"/></view>
                </view>
            </view>
            <view class="r-list">
                <view v-if="businessList.length===0">
                    <mNodata></mNodata>
                </view>
                <view  v-else class="l-box" v-for="(item,index) in businessList" :key="index">
                    <view class="b-num">
                        <view class="n-title" v-if="item.status==2">拼团结果：成功</view>
                        <view class="n-title" v-if="item.status==3">拼团结果：感谢参与</view>
                        <view class="n-money"><view class="n-money-text">{{item.name}}</view></view>
                    </view>
                    <view class="b-time">
                        <view class="t-title">{{item.created_at}}</view>
                    </view>
                </view>
            </view>
        </view>
<!--        <van-calendar-->
<!--                type="single"-->
<!--                :min-date="minDate"-->
<!--                :max-date="maxDate"-->
<!--                :show="beginShowData"-->
<!--                :default-date="defaultDate"-->
<!--                :title="'选择开始日期'"-->
<!--                :close-on-click-overlay="true"-->
<!--                @close="handleCloseData1"-->
<!--                @confirm="handleSubmitData1"-->
<!--        />-->
<!--        <van-calendar-->
<!--                type="single"-->
<!--                :min-date="minDate"-->
<!--                :max-date="maxDate"-->
<!--                :show="endShowData"-->
<!--                :default-date="defaultDate"-->
<!--                :title="'选择结束日期'"-->
<!--                :close-on-click-overlay="true"-->
<!--                @close="handleCloseData2"-->
<!--                @confirm="handleSubmitData2"-->
<!--        />-->
        <van-popup :show="beginShowData" position="bottom" :overlay="true"  @close="onClose($event)"
                   @touchmove.stop.prevent="moveHandle"
        >
            <van-datetime-picker
                    type="date"
                    title="选择日期"
                    :value="currentDate"
                    @cancel="handleCloseData1"
                    @confirm="handleSubmitData1"
            />
        </van-popup>

                <van-popup :show="endShowData" position="bottom" :overlay="true"  @close="onClose($event)"
                           @touchmove.stop.prevent="moveHandle"
                >
                    <van-datetime-picker
                            type="date"
                            title="选择结束日期"
                            :value="currentDate"
                            @cancel="handleCloseData2"
                            @confirm="handleSubmitData2"
                    />
                </van-popup>


        <van-popup :show="select_show" position="bottom" :overlay="true"  @close="onClose($event)"
                   @touchmove.stop.prevent="moveHandle"
        >
            <van-picker show-toolbar title="选择查询类型" :columns="columns" @cancel="onCancel($event)" @confirm="onConfirm($event)" @change="onChange($event)" />
        </van-popup>
    </view>
</template>

<script>
    export default {
        name: "groupBuyLog",
        data() {
            return {
                businessList:[],
                beginShowData:false,
                endShowData:false,
                minDate: new Date(2020, 0, 1).getTime(),
                maxDate: new Date().getTime(),
                defaultDate:new Date().getTime(),
                start_time:'',
                end_time:'',
                columns: ['显示全部', '成功', '失败'],
                select_show:false,
                selected_type:0,
                selected_type_name:'显示全部',
                page:1,
                is_load:0,
                currentDate: new Date().getTime(),
            }
        },
        mounted() {
            this.getBonusOrderLog()
        },
        onReachBottom() {  //分页加载请求数据
            if(this.is_load>0){
                this.page++
                this.getBonusOrderLog()
            }else{
                uni.showToast({
                    title:"没有更多数据啦",
                    icon:"none",
                })
            }
        },
        methods: {
            timestampToTime (cjsj) {
                let date = new Date(cjsj) //时间戳为10位需*1000，时间戳为13位的话不需乘1000
                let Y = date.getFullYear() + '-'
                let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'
                let D = date.getDate() + ' '
                return Y+M+D
            },
            moveHandle () {},
            //展示日期
            hanldeShowData1(res){
                this.beginShowData=true
            },
            //关闭日期弹窗
            handleCloseData1(res){
                this.beginShowData=false
            },
            //关闭结束日期弹窗
            handleCloseData2(res){
                this.endShowData=false
            },
            //选择开始日期完成后
            handleSubmitData1(res){
                // let year=res.detail.getFullYear()
                // let month=res.detail.getMonth()+1
                // let day=res.detail.getDate()
                // this.start_time=year+'-'+month+'-'+day
                this.start_time=this.timestampToTime(res.detail)
                this.beginShowData=false
                this.page=1
                this.is_load=0
                this.businessList=[]
                this.getBonusOrderLog()

            },
            //选择结束日期完成后
            handleSubmitData2(res){
                let year=res.detail.getFullYear()
                let month=res.detail.getMonth()+1
                let day=res.detail.getDate()
                this.end_time=year+'-'+month+'-'+day
                this.endShowData=false
            },
            clear(){
                this.start_time=''
                this.end_time=''
                this.selected_type=0
                this.selected_type_name='显示全部'
            },
            onChange(event) {
                const { picker, value, index } = event.detail;
            },
            onClose(event) { // 遮罩关闭
                this.select_show=false
                this.beginShowData=false
                this.endShowData=false
            },
            onCancel(event){  //选择器取消
                this.select_show=false
            },
            onConfirm(event){ //选择器确认
                const { picker, value, index } = event.detail;
                this.select_show=false
                this.selected_type=index
                this.selected_type_name=value
                this.page=1
                this.is_load=0
                this.businessList=[]
                this.getBonusOrderLog()
            },
            selectShow(){
                this.select_show=true
            },
            //获取列表
            async getBonusOrderLog(){
                uni.showLoading({})
                let resData =await this.$apis.getBonusOrderLog({
                    access_token: '',
                    page:this.page,
                    start_time:this.start_time,
                    type:this.selected_type
                })
                if(resData.code===0){
                    this.businessList.push(...resData.data.lists)
                    this.is_load=resData.data.is_load
                }
                uni.hideLoading()
            },
            submit(){ //点击搜索
                this.page=1
                this.is_load=0
                this.businessList=[]
                this.getBonusOrderLog()
            }
        },
    }
</script>
<style>
    page {
        background-color:#FAFAFA
    }
</style>
<style lang="less" scoped>
    .business-record{
        background-color: #ffffff;
        position: relative;
        width: 100%;
        /*margin-left: 50rpx;*/
        .r-data{
            position: fixed;
            background-color: #ffffff;
            width: 100%;
            height: 80rpx;
            display: flex;
            box-sizing: border-box;
            padding: 0 30rpx;
            justify-content: space-between;
            align-items: center;
            border-bottom: solid 1px #EDEDED;
            .d-time{
                font-size: 22rpx;
                color: #999999;
                margin-left: 10rpx;
                width: 100rpx;
                margin-top: 9rpx;
                line-height: 1.5;

            }
            .date_arrow_image{
                position: relative;
                width: 40rpx;
                height: 40rpx;
                /*margin-left: -120rpx;*/
            }
        }
        .r-list{
            width: 100%;
            box-sizing: border-box;
            padding: 80rpx 20rpx 0 20rpx;
            .l-box{
                box-sizing: border-box;
                border-bottom: solid 1px #EDEDED;
                padding: 40rpx 0;
                .b-num{
                    display: flex;
                    justify-content: space-between;
                    // line-height: 80rpx;
                    .n-title{
                        font-size: 26rpx;
                        color: #333333;

                    }
                    .n-money{
                        font-size: 26rpx;
                        color: #333333;
                        text-align: right;

                    }
                }
                .b-time{
                    padding-top: 20rpx;
                    display: flex;
                    justify-content: space-between;
                    // line-height: 80rpx;
                    .t-title{
                        font-size: 24rpx;
                        color: gray;
                    }
                    .t-status{
                        font-size: 24rpx;
                        color:#999999;
                    }
                }
            }
        }
    }
    .business_number{
        display: flex;
        flex-direction: row;
        width: 226rpx;
        /*border: solid 0.5px #999999;*/
        border-radius: 10px;
        font-size: 25rpx;
        margin-right: -9px;
    }
    .search_image{
        margin-top: 7rpx;
        height: 35rpx;
        width: 35rpx;
    }
    .date_image{
        /*margin-left: 12rpx;*/
        height: 40rpx;
        width: 40rpx;
    }
    .date_image_2{
        /*margin-left: 12rpx;*/
        height: 17rpx;
        width: 30rpx;
        transform:  translate(0,20%);
        /*margin-left: 10rpx;*/
    }
    .empty_img{
        margin-top: 200rpx;
        width: 520rpx;
        height: 360rpx;
    }
    .empty_text{
        color: #333333;
        font-size: 26rpx;
        margin-top: 20rpx;
    }
    .empty_box{
        text-align: center;
    }
    .button_1{
        width: 108rpx;
        border: none;
        background-color: #FF9502;
        font-size:26rpx;
        color: #ffffff;
    }
    .button_1:nth-child(1){
        margin-right: 10rpx;
    }
    .total_cash{
        font-size: 26rpx;
        color: #F19317;
    }
    .top_1_box{
        display: flex;
        flex-direction: row;
        margin-left: 20rpx;
    }
    .watch_all{
        margin-left: 20rpx;
        font-size: 25rpx;
        color: #333333;
        margin-top: 9rpx;
    }
    .n-money-text{
        margin-top: 20rpx;
        color:#999999;
    }
    .select_box{
        position: fixed;
        bottom: 0;
    }

</style>
